package cn.ekuma.epos.customerfinishing.model;

import com.openbravo.bean.BusinessPartner;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import com.openbravo.pos.base.AppLocal;
import com.openbravo.pos.util.IntegerUtils;

import cn.ekuma.data.ui.swing.AbstractDTOTableModel;
import cn.ekuma.epos.db.table.I_Customer;

public class CustomerTableModel extends AbstractDTOTableModel<BusinessPartner>{

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		BusinessPartner obj=this.getObj(rowIndex);
		switch(columnIndex){
		case 0:
			return obj.getTaxid();
		case 1:
			return obj.getSearchkey();
		case 2:
			return obj.getName();
		case 3:
			return obj.getCard();
		case 4:
			return obj.isVisible();
		case 5:
			return obj.getNotes();
		case 6:
			return obj.getMaxdebt();
		case 7:
			return Formats.TIMESTAMP.formatValue(obj.getCurdate());
		case 8:
			return obj.getCurdebt();
		case 9:
			return obj.getFirstname();
		case 10:
			return obj.getLastname();
		case 11:
			return obj.getEmail();
		case 12:
			return obj.getPhone();
		case 13:
			return obj.getPhone2();
		case 14:
			return obj.getFax();
		case 15:
			return obj.getAddress();
		case 16:
			return obj.getAddress2();
		case 17:
			return obj.getPostal();
		case 18:
			return obj.getCity();
		case 19:
			return obj.getRegion();
		case 20:
			return obj.getCountry();
		case 21:
			return obj.getScore();
		}
		return null;
	}

	public void setObject(int row, BusinessPartner obj) {
		objs.set(row, obj);
	}
	
   private static int[] doubleInt={8,21};
	
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		if(IntegerUtils.concat(columnIndex, doubleInt))
			return Double.class;
		return super.getColumnClass(columnIndex);
	}
	
	@Override
	public String[] getColumnNames() {
		
		return new String[]{
				AppLocal.getIntString("label.taxid"),
				AppLocal.getIntString("label.searchkey"),
				AppLocal.getIntString("label.name"),
				"CARD",
				"VISIBLE",
				
				AppLocal.getIntString("label.notes"),
				AppLocal.getIntString("label.maxdebt"),
				AppLocal.getIntString("label.curdate"),
				AppLocal.getIntString("label.curdebt"),
				
				AppLocal.getIntString("label.firstname"),
				AppLocal.getIntString("label.lastname"),
				AppLocal.getIntString("label.email"),
				AppLocal.getIntString("label.phone"),
				AppLocal.getIntString("label.phone2"),
				
				AppLocal.getIntString("label.fax"),
				AppLocal.getIntString("label.address"),
				AppLocal.getIntString("label.address2"),
				AppLocal.getIntString("label.postal"),
				AppLocal.getIntString("label.city"),
				
				AppLocal.getIntString("label.region"),
				AppLocal.getIntString("label.country"),
				AppLocal.getIntString("label.score")
		};
	}
	
	public static Field[] getQBFFields(){
		return new Field[]{
                //new Field(I_Customer.ID,        Datas.STRING,Formats.STRING,"ID"),
                new Field(I_Customer.TAXID,     Datas.STRING, Formats.STRING,AppLocal.getIntString("label.taxid")),
                new Field(I_Customer.SEARCHKEY, Datas.STRING,Formats.STRING,AppLocal.getIntString("label.searchkey")),
                new Field(I_Customer.NAME1,      Datas.STRING,Formats.STRING,AppLocal.getIntString("label.name")),
                new Field(I_Customer.CARD,      Datas.STRING,Formats.STRING,"CARD"),
                
                new Field(I_Customer.VISIBLE,   Datas.BOOLEAN, Formats.BOOLEAN, "VISIBLE"),
                new Field(I_Customer.NOTES,     Datas.STRING,Formats.STRING, AppLocal.getIntString("label.notes")),
                new Field(I_Customer.MAXDEBT,   Datas.DOUBLE, Formats.CURRENCY,AppLocal.getIntString("label.maxdebt")),
                new Field(I_Customer.CURDATE,   Datas.TIMESTAMP,Formats.TIMESTAMP,AppLocal.getIntString("label.curdate")),
                new Field(I_Customer.CURDEBT,   Datas.DOUBLE,Formats.CURRENCY,AppLocal.getIntString("label.curdebt")),
                
                new Field(I_Customer.FIRSTNAME, Datas.STRING, Formats.STRING,AppLocal.getIntString("label.firstname")),
                new Field(I_Customer.LASTNAME,  Datas.STRING,Formats.STRING,AppLocal.getIntString("label.lastname")),
                new Field(I_Customer.EMAIL,     Datas.STRING, Formats.STRING,AppLocal.getIntString("label.email")),
                new Field(I_Customer.PHONE,     Datas.STRING,Formats.STRING,AppLocal.getIntString("label.phone")),
                new Field(I_Customer.PHONE2,    Datas.STRING,Formats.STRING,AppLocal.getIntString("label.phone2")),
                
                new Field(I_Customer.FAX,       Datas.STRING, Formats.STRING, AppLocal.getIntString("label.fax")),
                new Field(I_Customer.ADDRESS,   Datas.STRING,Formats.STRING,AppLocal.getIntString("label.address")),
                new Field(I_Customer.ADDRESS2,  Datas.STRING,Formats.STRING,AppLocal.getIntString("label.address2")),
                new Field(I_Customer.POSTAL,    Datas.STRING,Formats.STRING,AppLocal.getIntString("label.postal")),
                new Field(I_Customer.CITY,      Datas.STRING,Formats.STRING, AppLocal.getIntString("label.city")),
                
                new Field(I_Customer.REGION,    Datas.STRING,Formats.STRING,AppLocal.getIntString("label.region")),
                new Field(I_Customer.COUNTRY,   Datas.STRING,Formats.STRING,AppLocal.getIntString("label.country")),
                //new Field(I_Customer.TAXCATEGORY,Datas.STRING,Formats.STRING ,"TAXCATEGORY" ),
                //new Field(I_Customer.CATEGORY,  Datas.STRING,Formats.STRING,CustomerCategory.class),
                new Field(I_Customer.APPPASSWORD,Datas.STRING,Formats.STRING, AppLocal.getIntString("Label.Password"))
                
               //new Field(I_Customer.LASTMODIFIED,Datas.TIMESTAMP, Formats.TIMESTAMP)
            };
	}
}
